#include <controls/combobox/cximuticombobox.h>
#include <private/combobox/cxicombobox_p.h>


ComboItem::ComboItem(const QString& display, const QString& data, const QVariant& tag, const QVector<QString>& filterWords)
{
	this->display = display;
	this->data = data;
	this->tag = tag;
	this->filterWords = filterWords;
}

CxiMutiComboBox::CxiMutiComboBox(QWidget* parent) : QWidget(parent), d_ptr(new CxiMutiComboBoxPrivate(this))
{

}

CxiMutiComboBox::~CxiMutiComboBox()
{
	delete d_ptr;
}
void CxiMutiComboBox::setPopupVisible(bool visible)
{
	Q_D(CxiMutiComboBox);
	d->setPopupVisible(visible);
}
void CxiMutiComboBox::addItem(const QString& display, const QString& data, const QVariant& tag, const QVector<QString>& filterWords = {})
{
	Q_D(CxiMutiComboBox);
	ComboItem item(display, data, tag, filterWords);
	d->addItem(item);
}
void CxiMutiComboBox::addItem(const ComboItem& item)
{
	Q_D(CxiMutiComboBox);
	d->addItem(item);
}
void CxiMutiComboBox::addItems(const QList<ComboItem>& items)
{
	Q_D(CxiMutiComboBox);
	for (auto& item: items)
	{
		d->addItem(item);
	}
}

QVector<QVariant> CxiMutiComboBox::getTags() const
{
	Q_D(const CxiMutiComboBox);
	return d->getTags();
}

QVector<QString> CxiMutiComboBox::getDatas() const
{
	Q_D(const CxiMutiComboBox);
	return d->getDatas();
}

bool ComboItem::hasSubString(const QString& subString) const
{
	if (display.contains(subString, Qt::CaseInsensitive))
		return true;

	for (const auto& alias : filterWords)
	{
		if (alias.contains(subString, Qt::CaseInsensitive))
			return true;
	}
	return false;
}

